/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import controlo.ControloProdutos;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import modelo.ModeloTabela;
import modelo.Modelo_produtos;
import utilizador_bd.ConectBD;

/**
 *
 * @author Daniel
 */
public final class Produtos extends javax.swing.JFrame {
ConectBD conectprod = new ConectBD();
ConectBD conect = new ConectBD();


modelo.Modelo_produtos prod = new Modelo_produtos();
controlo.ControloProdutos control = new ControloProdutos();


float total=0;


private String SQL;
    /**
     * Creates new form Produtos
     */
    public Produtos() {
        
       initComponents();
 conectprod.conexao();
        conect.conexao();
       
       
       jTextField2lucro.setEnabled(false);
              jTextField1valortotal.setEnabled(false);
              jTextField1codprod.setEnabled(false);

       jTextField1valortotal.setText(String.valueOf(total));    

       SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd");
       Date hoje = new Date();
       jFormattedTextField1data.setText(df.format(hoje));
       
       
       
       SimpleDateFormat hora = new SimpleDateFormat("HH:mm:ss.SSS");
      Date agora = new Date();
       jFormattedTextField1hora.setText(hora.format(agora));
        
        
        
       
       preencherTabela("select * from fornecedores inner join produtos on produtos.fornecedores = fornecedores.cod_fornecedor");

         //preencherTabela("select * from produtos order by descricao");

               

 try {
     conect.executaSQL("select * from fornecedores order by designacao");

        jComboBox1fornecedores.removeAllItems();     
     conect.re.first();
            do{
                jComboBox1fornecedores.addItem(conect.re.getString("designacao"));
            }while (conect.re.next());
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Erro na combo!"+ex);
        }
    }
 
        /*try {  conect.executaSQL("select * from iva order by descricao");
        jComboBox1iva.removeAllItems();
        
            conect.re.first();
            do{
                jComboBox1iva.addItem(conect.re.getString("ivaprod"));
            }while (conect.re.next());
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(rootPane, "Erro na combo!"+ex);
        }
        */
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField4 = new javax.swing.JTextField();
        jTextField6 = new javax.swing.JTextField();
        jButton2 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jTextField1descricao = new javax.swing.JTextField();
        jTextField2lucro = new javax.swing.JTextField();
        jTextField7valorvenda = new javax.swing.JTextField();
        jButton1novo = new javax.swing.JButton();
        jButton3gravar = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5logout = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField1quantidade = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextField1valortotal = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jComboBox1fornecedores = new javax.swing.JComboBox();
        jLabel11 = new javax.swing.JLabel();
        jTextField1precocompra = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jTextField1iva = new javax.swing.JTextField();
        jFormattedTextField1data = new javax.swing.JFormattedTextField();
        jFormattedTextField1hora = new javax.swing.JFormattedTextField();
        jLabel3 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel13 = new javax.swing.JLabel();
        jTextField1codprod = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();

        jTextField4.setText("jTextField4");

        jTextField6.setText("jTextField6");

        jButton2.setText("jButton2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Produto");

        jLabel2.setText("Lucro");

        jLabel4.setText("Iva");

        jLabel5.setText("Preço Venda");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);

        jTextField2lucro.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField2lucroMouseClicked(evt);
            }
        });

        jButton1novo.setText("novo");

        jButton3gravar.setText("gravar");
        jButton3gravar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3gravarActionPerformed(evt);
            }
        });

        jButton4.setText("Editar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5logout.setText("LogOut");
        jButton5logout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5logoutActionPerformed(evt);
            }
        });

        jButton6.setText("Eliminar");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jLabel6.setText("Quantidade");

        jLabel7.setText("Hora");

        jLabel8.setText("Data");

        jLabel9.setText("Valor Total");

        jTextField1valortotal.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jTextField1valortotal.setForeground(new java.awt.Color(255, 0, 0));
        jTextField1valortotal.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField1valortotalMouseClicked(evt);
            }
        });
        jTextField1valortotal.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1valortotalActionPerformed(evt);
            }
        });

        jLabel10.setText("Fornecedores");

        jComboBox1fornecedores.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel11.setForeground(new java.awt.Color(255, 51, 51));
        jLabel11.setText("Inserção Compras - Produtos");

        jLabel12.setText("PreçoCompra");

        jTextField1iva.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTextField1ivaMouseClicked(evt);
            }
        });

        jFormattedTextField1data.setText("jFormattedTextField1");

        jFormattedTextField1hora.setText("jFormattedTextField1");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(204, 0, 51));
        jLabel3.setText("€");

        jButton1.setText("Atualizar Total");
        jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton1MouseClicked(evt);
            }
        });

        jLabel13.setText("Cod_Produto");

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setForeground(new java.awt.Color(204, 0, 51));
        jLabel14.setText("€");

        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel15.setForeground(new java.awt.Color(204, 0, 51));
        jLabel15.setText("€");

        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel16.setForeground(new java.awt.Color(204, 0, 51));
        jLabel16.setText("€");

        jLabel17.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel17.setForeground(new java.awt.Color(255, 0, 0));
        jLabel17.setText("%");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addGroup(jPanel1Layout.createSequentialGroup()
                                    .addComponent(jLabel2)
                                    .addGap(30, 30, 30)
                                    .addComponent(jTextField2lucro, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel6)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField1quantidade))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField7valorvenda, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1precocompra, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel14))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField1descricao, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jTextField1codprod, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(4, 4, 4)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addGap(26, 26, 26)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel8)
                                        .addGap(18, 18, 18)
                                        .addComponent(jFormattedTextField1data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jTextField1iva, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jLabel17))
                                    .addComponent(jLabel11)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addGap(18, 18, 18)
                                        .addComponent(jFormattedTextField1hora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel16)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jButton1))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addComponent(jButton1novo)
                                                .addGap(77, 77, 77)
                                                .addComponent(jButton3gravar)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jButton4))
                                            .addComponent(jLabel9))
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(32, 32, 32)
                                                .addComponent(jTextField1valortotal, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(jLabel3))
                                            .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(31, 31, 31)
                                                .addComponent(jButton6)))))
                                .addGap(18, 18, 18)
                                .addComponent(jButton5logout))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(56, 56, 56)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 614, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel10)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jComboBox1fornecedores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 29, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(5, 5, 5)
                        .addComponent(jLabel11)
                        .addGap(46, 46, 46)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(jTextField1iva, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel17))
                        .addGap(40, 40, 40)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jFormattedTextField1hora, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel8)
                            .addComponent(jFormattedTextField1data, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(jTextField1valortotal, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1novo)
                            .addComponent(jButton3gravar)
                            .addComponent(jButton4)
                            .addComponent(jButton5logout)
                            .addComponent(jButton6))
                        .addGap(35, 35, 35))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(55, 55, 55)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jTextField1codprod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel1)
                            .addComponent(jTextField1descricao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(15, 15, 15)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jTextField1precocompra, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel12)
                            .addComponent(jLabel14))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5)
                            .addComponent(jTextField7valorvenda, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel15))
                        .addGap(19, 19, 19)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(jTextField1quantidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jTextField2lucro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel10)
                            .addComponent(jComboBox1fornecedores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(76, 76, 76))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton3gravarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3gravarActionPerformed
        
        
        prod.setDescricao(jTextField1descricao.getText());
        prod.setLucro(jTextField2lucro.getText());
        prod.setValorvendap(jTextField7valorvenda.getText());
        prod.setData(jFormattedTextField1data.getText());
        prod.setHora(jFormattedTextField1hora.getText());
        prod.setValortotal(jTextField1valortotal.getText());
        prod.setQuantidade(jTextField1quantidade.getText());
        prod.setPrecoCompra(jTextField1precocompra.getText());
        prod.setIva(jTextField1iva.getText());
        prod.setFornecedores((String)jComboBox1fornecedores.getSelectedItem());

                    control.Inserirempregados(prod);

                 
        //conect.executaSQL("select * from fornecedores where designacao='"+jComboBox1fornecedores.getSelectedItem()+"'");
       // conect.re.first();
            //   prod.setFornecedores(conect.re.getString("cod_fornecedor"));

        /*conect.executaSQL("select * from iva where ivaprod='"+jComboBox1iva.getSelectedItem()+"'");
        conect.re.first();
        
        prod.setIva(conect.re.getString("cod_iva"));   */
        
           
            preencherTabela("select * from produtos order by descricao");

     // preencherTabela("select * from empregados inner join funcao on empregados.funcao = funcao.id_funcao");

    }                                               

    
    
    public void preencherTabela(String SQL){
        ArrayList dados = new ArrayList();
        
        String [] Colunas = new String[]{"Cod_Prod", "Descrição","Fornecedor", "PreçoCompra","Iva","ValorVendaProd", "Lucro","ValorTotal" };
        
        conect.executaSQL(SQL);
          try {
              conect.re.first();
              
                do{
         dados.add(new Object[]{conect.re.getString("cod_prod"),conect.re.getString("descricao"),conect.re.getString("fornecedores"),conect.re.getString("precocompra"),conect.re.getString("iva"),conect.re.getString("valorvendap"),conect.re.getString("lucro"),conect.re.getString("valortotal")});
     } while(conect.re.next());
     
          } catch (SQLException ex) {
           JOptionPane.showMessageDialog(null, "Erro no array!\n Erro:" +ex.getMessage());
          }
          
        ModeloTabela modelo  = new ModeloTabela(dados, Colunas);
     
     jTable1.setModel(modelo);
     jTable1.getColumnModel().getColumn(0).setPreferredWidth(70);
     jTable1.getColumnModel().getColumn(0).setResizable(false);
     jTable1.getColumnModel().getColumn(1).setResizable(false);
     jTable1.getColumnModel().getColumn(1).setPreferredWidth(100);
     jTable1.getColumnModel().getColumn(2).setResizable(false);
     jTable1.getColumnModel().getColumn(2).setPreferredWidth(85);
     jTable1.getColumnModel().getColumn(3).setResizable(false);
     jTable1.getColumnModel().getColumn(3).setPreferredWidth(75);
     jTable1.getColumnModel().getColumn(4).setResizable(false);
     jTable1.getColumnModel().getColumn(4).setPreferredWidth(85);
     jTable1.getColumnModel().getColumn(5).setResizable(false);
     jTable1.getColumnModel().getColumn(5).setPreferredWidth(90);
     jTable1.getColumnModel().getColumn(6).setResizable(false);
     jTable1.getColumnModel().getColumn(6).setPreferredWidth(90);
 jTable1.getColumnModel().getColumn(7).setResizable(false);
     jTable1.getColumnModel().getColumn(7).setPreferredWidth(90);
     jTable1.getTableHeader().setReorderingAllowed(false);
     jTable1.setAutoResizeMode(jTable1.AUTO_RESIZE_OFF);
     jTable1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
     
    
        
           
              }//GEN-LAST:event_jButton3gravarActionPerformed

    private void jButton5logoutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5logoutActionPerformed

        int resposta ;
        
        resposta=JOptionPane.showConfirmDialog(null, "Quer mesmo sair do programa?");       

        if (resposta == JOptionPane.YES_OPTION) {

        dispose();



} else {


}    }//GEN-LAST:event_jButton5logoutActionPerformed

    private void jTextField1valortotalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1valortotalActionPerformed



    }//GEN-LAST:event_jTextField1valortotalActionPerformed

    private void jTextField1valortotalMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1valortotalMouseClicked

                
        
        //total = total + Float.parseFloat(jTextField1precocompra.getText())* Integer.parseInt(jTextField1quantidade.getText())*(1 + Float.parseFloat(jTextField1iva.getText()));
        //jTextField1valortotal.setText(String.valueOf(total));    



// TODO add your handling code here:
    }//GEN-LAST:event_jTextField1valortotalMouseClicked

    private void jTextField2lucroMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField2lucroMouseClicked
total = total + Float.parseFloat(jTextField7valorvenda.getText ())- Float.parseFloat(jTextField1precocompra.getText());
        jTextField2lucro.setText(String.valueOf(total));  

    }//GEN-LAST:event_jTextField2lucroMouseClicked

    private void jTextField1ivaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTextField1ivaMouseClicked
total = total + Float.parseFloat(jTextField1precocompra.getText())* Integer.parseInt(jTextField1quantidade.getText())*(1 + Float.parseFloat(jTextField1iva.getText()));
        jTextField1valortotal.setText(String.valueOf(total));    
    }//GEN-LAST:event_jTextField1ivaMouseClicked

    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseClicked
total = total + Float.parseFloat(jTextField1precocompra.getText())* Integer.parseInt(jTextField1quantidade.getText())*(1 + Float.parseFloat(jTextField1iva.getText()));
        jTextField1valortotal.setText(String.valueOf(total));    }//GEN-LAST:event_jButton1MouseClicked

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
       try {
            PreparedStatement pft;
            pft = conect.con.prepareStatement("delete from produtos where cod_prod='" +jTextField1codprod.getText()+"'");
            pft.executeUpdate();
        
            preencherTabela("select * from produtos inner join fornecedores on produtos.fornecedores = fornecedores.cod_fornecedor");
            JOptionPane.showMessageDialog(rootPane, "Eliminado com sucesso:");
        } catch (SQLException ex) {
           JOptionPane.showMessageDialog(rootPane, "Erro na inserção!\n Erro:" +ex.getMessage());
        }
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        try {
     int quantidade,cod, fornecedores;
     String  morada,data,hora;
     float valorvendap, lucro, iva,valortotal, precocompra;
     
     
         String nome = "" + jTable1.getValueAt(jTable1.getSelectedRow(), 1);
        conect.executaSQL("select * from produtos where descricao ='"+nome+"'");

        conect.re.first();
        

        //bi=conect.re.getInt("bi");
        //jTextFieldbi.setText(String.valueOf(bi));
        
       
        valorvendap=conect.re.getFloat("valorvendap");
        jTextField7valorvenda.setText(String.valueOf(valorvendap));
        
        cod =  conect.re.getInt("cod_prod");
        jTextField1codprod.setText(String.valueOf(cod));
        
          lucro =  conect.re.getFloat("lucro");
        jTextField2lucro.setText(String.valueOf(lucro));
        
        iva =  conect.re.getFloat("iva");
        jTextField1iva.setText(String.valueOf(iva));

        valortotal =  conect.re.getFloat("valortotal");
        jTextField1valortotal.setText(String.valueOf(valortotal));
            
        precocompra =  conect.re.getFloat("precocompra");
        jTextField1precocompra.setText(String.valueOf(precocompra));
        
        
        
         quantidade=conect.re.getInt("quantidade");
        jTextField1quantidade.setText(String.valueOf(quantidade));
        
        hora=conect.re.getString("hora");
        jFormattedTextField1hora.setText(hora);
        
        data=conect.re.getString("data");
        jFormattedTextField1data.setText(data);
        
        
       // fornecedores=conect.re.getInt("fornecedores");
         //jComboBox1fornecedores.setSelectedIndex(fornecedores);

                 jTextField1descricao.setText(nome);

        
        
        
        

    } catch (SQLException ex) {
JOptionPane.showMessageDialog(rootPane, "Erro ao pesquisar na tabela!"+ex.getMessage());
        
        

        

}
    }//GEN-LAST:event_jTable1MouseClicked

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        
        
        prod.setDescricao(jTextField1descricao.getText());
        prod.setLucro(jTextField2lucro.getText());
        prod.setValorvendap(jTextField7valorvenda.getText());
        prod.setData(jFormattedTextField1data.getText());
        prod.setHora(jFormattedTextField1hora.getText());
        prod.setValortotal(jTextField1valortotal.getText());
        prod.setQuantidade(jTextField1quantidade.getText());
        prod.setPrecoCompra(jTextField1precocompra.getText());
        prod.setIva(jTextField1iva.getText());
          prod.setFornecedores((String)jComboBox1fornecedores.getSelectedItem());
                }//GEN-LAST:event_jButton4ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Produtos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Produtos().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton1novo;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3gravar;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5logout;
    private javax.swing.JButton jButton6;
    private javax.swing.JComboBox jComboBox1fornecedores;
    private javax.swing.JFormattedTextField jFormattedTextField1data;
    private javax.swing.JFormattedTextField jFormattedTextField1hora;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1codprod;
    private javax.swing.JTextField jTextField1descricao;
    private javax.swing.JTextField jTextField1iva;
    private javax.swing.JTextField jTextField1precocompra;
    private javax.swing.JTextField jTextField1quantidade;
    private javax.swing.JTextField jTextField1valortotal;
    private javax.swing.JTextField jTextField2lucro;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7valorvenda;
    // End of variables declaration//GEN-END:variables
}
